<template>
  <div class="count">
    <h2>当前的和为：{{ sum }}</h2>
    <h2>十倍和为：{{ bigSum }}</h2>
    <div>
      <select v-model.number="n">
        <option value="1">1</option>
        <option value="2">2</option>
        <option value="3">3</option>
      </select>
      <button @click="increment">+</button>
      <button @click="decrement">-</button>
      <button @click="incrementOdd">当前为奇数+</button>
      <button @click="incrementWait">延迟500ms+</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      n: 1,
    };
  },
  methods: {
    increment() {
      this.$store.commit("increment", this.n);
    },
    decrement() {
      this.$store.commit("decrement", this.n);
    },
    incrementOdd() {
      this.$store.dispatch("incrementOdd", this.n);
    },
    incrementWait() {
      this.$store.dispatch("incrementWait", this.n);
    },
  },
  computed: {
    sum() {
      return this.$store.state.sum;
    },
    bigSum() {
      return this.$store.getters.bigSum;
    },
  },
  mounted() {
    console.log(this.$store);
  },
};
</script>

<style scoped></style>
